#!/usr/bin/python3
# -*- coding:utf-8 -*-
""""
   @Author: 叶建伟
   @Email: yejw46507@hundsun.com
   @Time: 2023/5/12 16:28
   @File: dataTest.py
   生成反洗钱sql数据
"""
import uuid

from faker import Faker
import random
from DataTest.databases import OracleUtil, MysqlUtil, OceanBaseUtil, PostgreSqlUtil, DaMengUtil

from DataTest.sqlmontage import randomInfo
from DataTest.sqlmontage.SQLMontage import get_sql_key, montage_sql_value, read_file

fake = Faker(locale='zh_CN')
# db = MysqlUtil('root', 'fxq5@123', '10.20.46.217', port=33061)
db = PostgreSqlUtil('postgresql','fxq123','10.20.37.112',server='hsrcm',port='5432')
from CommonScripts.blade import python_exec_sql


def montage_sql(**kwargs):
    table = kwargs.get('table')
    print(table)
    sql_list = kwargs.get('sql_list')
    env = kwargs.get('env')
    sql = read_file(table)
    for key, value in sql.items():
        table_value = {}
        for key_1, value_1 in value[0].items():
            keyLower = key_1.lower()
            table_value.update({keyLower: value_1})
        table_key = get_sql_key(table=table)
        values = montage_sql_value(table=table_value, sql_list=sql_list)
        sql = table_key.lower()+values
        print(sql)
        # db.execsql(sql)
        python_exec_sql(sql, env=env)


if __name__ == "__main__":
    occupation_code_list = ['99']
    for j in range(1,39):
        occupation_code_list = occupation_code_list+[str(j)]
    print(occupation_code_list)

    for i in range(10000,100000):
        client_list = randomInfo.generate_info()
        client_id = inner_client_id = '1203000'+str(i)
        client_type = '0'
        agency_no = '002'
        apply_date = 20241125
        match_amount = i
        # client_name = ''
        # client_full_name = client_name
        # id_no = 'CP0009'
        ta_no = '6H'
        batch_no = str(i)
        fund_account = 'FA'+client_id
        benefit_id = 'benefit122616000009'
        benefit_name = '受益人00019'
        process_instance_id = str(i)
        sql_list={'apply_date':apply_date,'client_id': client_id,'inner_client_id': inner_client_id,'batch_no':batch_no,
                  'client_type': client_type,'agency_no':agency_no,'fund_account':fund_account,
                  'ta_no':ta_no,'benefit_id':benefit_id,'benefit_name':benefit_name,'process_instance_id':process_instance_id}
        sql_list.update(client_list)

        contact_address = randomInfo.get_address()
        sql_list.update({'contact_address':contact_address})
        # print(sql_list)
        sql_list.update({'fund_acc_status':'0'})
        # sql_list.update({'client_name': 'abcdef'})
        sql_list.update({'occupation_code':random.choice(occupation_code_list)})
        sql_list.update({'gender_code':'1'})
        sql_list.update({'nationality_code':'CHN'})
        # apply_date = 20231225
        occur_date = 20241125

        sql_list.update({'apply_date': apply_date})
        sql_list.update({'occur_date': occur_date})
        serial_no = uuid.uuid4().hex
        apply_no = uuid.uuid4().hex
        sql_list.update({'serial_no': serial_no})
        sql_list.update({'apply_no': apply_no})
        sql_list.update({'fund_account':fund_account})

        # montage_sql(table='amlci_risk_event_info', sql_list=sql_list)
        # montage_sql(table='amlbd_client', sql_list=sql_list)
        # sql_list.update({'id_no': id_no,'fund_account':fund_account,'client_name':client_name,'client_full_name':client_full_name})
        montage_sql(table='fnd_client', sql_list=sql_list)
        montage_sql(table='fnd_fund_account', sql_list=sql_list)

        # montage_sql(table='amlbd_client',sql_list=sql_list)
        # montage_sql(table='amlci_task_measure',sql_list=sql_list)

        # montage_sql(table='amlls_baseinfo', sql_list=sql_list)
        # montage_sql(table='amlls_client', sql_list=sql_list)











